home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / RTF / elements.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  130 lines

  1. /* $Header: /usr/people/pcd/Src/RTF/RCS/elements.h,v 1.1 92/11/23 12:58:51 pcd Exp Locker: pcd $
  2.  */
  3.  
  4. #ifndef __elements_h
  5. #define __elements_h
  6.  
  7. #include "space.h"
  8. #include "textflow.h"
  9.  
  10. class View;
  11.  
  12. class ParagraphFormat{
  13. public:
  14.   ParagraphFormat();
  15.  
  16.   enum {max_tabs = 10};
  17.   enum {quad_left, quad_center, quad_right, quad_full} justification;
  18.  
  19.   Inches left_indent;
  20.   Inches right_indent;
  21.   Inches first_indent;
  22.   Inches space_before;
  23.   Inches space_after;
  24.   Inches space_between;
  25.  
  26.   void normal();
  27.  
  28.   void add_tab_stop(Inches ts)
  29.     { if(tabqty < max_tabs)
  30.     stops[tabqty++] = ts;
  31.     };
  32.  
  33.   int     tabs() const
  34.     { return tabqty; }
  35.  
  36.   void    newtabs()
  37.     { tabqty=0; }
  38.   
  39.   static void default_tab_width(Inches w) 
  40.     { default_tab_width_ = w; };
  41.   // This must be set before any calls to tab() are made.
  42.  
  43.   Inches tab(int n) const
  44.     // tab(3) returns 2" if there are only 3 tab stops
  45.     { return n < tabqty ? stops[n] : (double)(n+1) * default_tab_width_; };
  46.  
  47. private:
  48.   Inches stops[max_tabs];
  49.   int tabqty;
  50.   static Inches default_tab_width_;
  51. };
  52.  
  53.  
  54. class CharacterFormat{
  55. public:
  56.   CharacterFormat()
  57.     { plain(); };
  58.   void plain()
  59.     { bold = italic = underline = font_family = super = sub = 0;
  60.       foreground = 0;
  61. #ifdef FONT_SIZES
  62.       size = 24;
  63. #endif
  64.     };
  65.  
  66. #ifdef FONT_SIZES
  67.   char size;
  68. #endif
  69.  
  70.   char bold, italic, underline;
  71.   char font_family, super, sub;
  72.   int foreground;
  73.   unsigned long fg_pixel;
  74. };
  75.  
  76.  
  77. /***** formatting elements ******/
  78.  
  79. class NewLineFlow : public TextFlow{
  80. public:
  81.   NewLineFlow(TextFlow& parent, TextPosition first, TextPosition last)
  82.     : TextFlow(parent, first, last) {};
  83.  
  84.   Qty character_shape(TextPosition, Qty, Extent, Extent&, int) const;
  85.  
  86.   virtual Coord font_ascent() const
  87.     { return 1; }; // must be > 0
  88.  
  89.   virtual Coord space_after() const
  90.     { return 0; };
  91. };
  92.  
  93. class ParagraphFlow : public TextFlow{
  94. public:
  95.   ParagraphFlow(TextFlow& p, TextPosition f, TextPosition l,
  96.         const ParagraphFormat& fmt, View& v)
  97.     : TextFlow(p, f, l) { view_ = &v; fmt_ = fmt; };
  98.  
  99.   void line_shape(TextPosition, Extent&) const;
  100.  
  101.   const View& view() const
  102.     { return *view_; };
  103.  
  104. protected:
  105.   View* view_;
  106.   ParagraphFormat fmt_;
  107. };
  108.  
  109.  
  110. class TabFlow : public TextFlow{
  111. public:
  112.   TabFlow(TextFlow& p, TextPosition f, TextPosition l,
  113.       ParagraphFormat& pf, View& v)
  114.     : TextFlow(p, f, l) { view_ = &v; fmt_ = pf; };
  115.  
  116.   Qty character_shape(TextPosition, Qty, Extent, Extent&, int) const;
  117.  
  118.   Coord next_tab_stop(Coord here) const;
  119.  
  120.   const View& view() const
  121.     { return *view_; };
  122.  
  123. protected:
  124.   View* view_;
  125.   ParagraphFormat fmt_;
  126. };
  127.  
  128. #endif
  129.  
  130.